package com.example.mapp;

import com.example.entity.SpotCheckCache;
import com.example.entity.SpotCheckItem;
import com.example.entity.SpotCheckPlan;
import com.example.entity.SpotObjectCensus;
import com.example.mapp.buildSql.SpotCheckItemMappSql;
import com.example.mapp.buildSql.SpotCheckPlanMappSql;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 维保计划的检查项
 */
@Mapper
public interface SpotCheckItemMapp {

    // 新增数据
    @Insert(" insert into spot_check_item (plan_id,item_id,custom_name,is_custom )" +
            "value " +
            "(#{planId},#{itemId},#{customName},#{isCustom})")
    public int insert(SpotCheckItem spotCheckItem) throws Exception;

    //通过id查询SQL语句
    @SelectProvider(type = SpotCheckItemMappSql.class,method = "findlists")
    public List<SpotCheckItem> findList(SpotCheckItem spotCheckItem) throws Exception;

    // 删除数据
    @Delete("delete from spot_check_item where plan_id=#{planId} and is_custom='N'")
    public void delete(Long id) throws Exception;

    // 通过Id删除数据
    @Delete("delete from spot_check_item where id=#{id}")
    public void deleteById(Long id) throws Exception;

    // 通过计划Id删除
    @Delete("delete from spot_check_item where plan_id=#{planId}")
    public void deleteByPlanId(Long id) throws Exception;

    // 导出excel
    @SelectProvider(type = SpotCheckItemMappSql.class,method = "findListExcel")
    List<HashMap<String, Object>> findListExcel(SpotCheckItem checkItem);


    // App端查询检查项数据
    @SelectProvider(type = SpotCheckItemMappSql.class,method = "findCheckItemApp")
    List<Map<String, Object>> findCheckItemApp(Map map);

    // App端新增检查项数据
    @Insert(" insert into spot_object_census (plan_id,user_id,implement_object,head_man,check_man,check_record,elevator_id," +
            "check_item_id,check_item_name,create_by,create_date,del_flag,obj_id,remarkes,pic_url,result_evaluate,opinion,sign_photo)" +
            "value " +
            "(#{planId},#{userId},#{implementObject},#{headMan},#{checkMan},#{checkRecord},#{elevatorId},#{checkItemId},#{checkItemName},#{createBy},#{createDate},#{delFlag},#{objId},#{remarkes},#{picUrl},#{resultEvaluate},#{opinion},#{signPhoto})")
    void addCheckItemApp(SpotObjectCensus object) throws Exception;

    // App端获取电梯信息
    @SelectProvider(type = SpotCheckItemMappSql.class,method = "findElevatorInfoApp")
    List<Map<String, Object>> findElevatorInfoApp(Map map);

    // App端新增缓存数据
    @Insert(" insert into spot_check_cache (plan_id,name,check_item_id,create_by,spot_check_item_id,check_name,is_checked,implement_object_id,remarkes,pic_url,result_evaluate,opinion)" +
            "value " +
            "(#{planId},#{name},#{checkItemId},#{createBy},#{spotCheckItemId},#{checkName},#{isChecked},#{implementObjectId},#{remarkes},#{picUrl},#{resultEvaluate},#{opinion})")
    void insertCache(SpotCheckCache cache);

    // App端查询缓存数据进行返回
    @SelectProvider(type = SpotCheckItemMappSql.class,method = "returnFindCache")
    List<Map<String, Object>> returnFindCache(SpotCheckCache cache);

    @Delete("delete from spot_check_cache where plan_id=#{planId} and implement_object_id=#{implementObjectId} ")
    void deleteCache(SpotCheckCache checkCache);
}
